package edu.berkeley.drivingbuddy;

import android.location.Location;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

public class Datastore {

	private List<ResultGroup> mResultGroups;
    private int goalScore = 70;
	private Map<Integer, ResultObj> mResults;

	public Datastore() {
		mResultGroups = new ArrayList<ResultGroup>();
		mResults = new HashMap<Integer, ResultObj>();
	}

	public void registerNewResult(ResultObj result) {
		mResults.put(result.getUniqueResultId(), result);
	}

	public ResultGroup queryForOrCreateResultGroup(Location start, Location end) {
		float distThreshold = 100;
		for (ResultGroup group : mResultGroups) {
			if ((group.getStartLocation().distanceTo(start) <= distThreshold)
					&& (group.getStartLocation().distanceTo(start) <= distThreshold))
				return group;
		}
		ResultGroup resultGroup = new ResultGroup(start, end);
		mResultGroups.add(resultGroup);
		return resultGroup;
	}

	public List<ResultGroup> getResultGroups() {
		return mResultGroups;
	}

	public ResultObj getResultById(int id) {
		return mResults.get(id);
	}

    public void setGoalScore(int score) {
        goalScore = score;
    }
    public int getGoalScore() {
        return goalScore;
        
    }
}
